Function execution methods that execute programs containing multiple functions composed of multiple instructions written in language such as Java are utilized recently in many applications and such language such as Java is generally executed in an area of a memory of a JVM after being compiled into byte-code of the JVM.
FIG. 1 is a conceptual diagram showing function record areas in which functions necessary to execute a program are recorded.
A program is executed generally as nested invocation of functions (methods). That is, as shown in FIGS. 1(a), (b) and (c), regarding functions necessary to execute a program, an invoked function to be executed is invoked by an invoking function in execution, a new function record area according to a format of the invoked function is stacked and secured on a function record area (frame) of the invoking function in execution that are secured in a stack area of a memory, the invoked function which has been invoked is executed utilizing the secured function record area and the stacked function record area which has become unnecessary is discarded after completion of execution of the invoked function.
The function record area stacked on the top, in which the function in execution is recorded, is called a top-frame. In FIG. 1(a) wherein a function F is in execution, the function record area of the function F is the top-frame.
When the function F as an invoking function invokes a function G which is an invoked function, a function record area to execute the function G is stacked in the stack area to be the top-frame as shown in FIG. 1(b). After completion of execution of the function G, execution results of the function G are transferred to the function F and the corresponding function record area is discarded, so that the state becomes as in FIG. 1(a) that is the state before invocation.
It should be noted in FIG. 1(b) that, when the function G as an invoking function further invokes another function H which is an invoked function, a function record area to execute the function H is stacked in the stack area to be the top-frame as shown in FIG. 1(c). After completion of execution of the function H, execution results of the function H are transferred to the function G and the corresponding function record area is discarded, so that the state becomes as in FIG. 1(b) that is the state before invocation.
Here, when the execution results of the function H as an invoked function invoked by the function G which is an invoking function are transferred to the function F as execution results of the function G, the invocation of the function H is called tail-recursive invocation. In tail-recursive invocation, the function record areas of the functions H and G are discarded one after another, after completion of execution of the function H.
However, to stack many function record areas in the stack area may cause the stack area to overflow and a problem may arise in some cases in execution of a program.
Moreover, a problem of decrease in total execution speed may arise because of the processing load required for stacking and discarding function record areas.
The present invention has been made in consideration of these situations, and it is a main object thereof to provide a function execution method which can reduce the possibility of occurrence of a problem in execution of a program due to function record areas overflowing a stack area and reduce the processing load required for stacking and discarding areas to improve total execution speed by not stacking a new function record area but utilizing a function record area, in which an invoking function is recorded, as a function record area, in which an invoked function is recorded, when it is judged that invocation by an invoking function is tail-recursive invocation; a function execution apparatus to which the method is applied; a computer program for realizing the apparatus; and a recorded medium in which the computer program is recorded.
Another object of the present invention is to provide a function execution method, and the like, that does not require any special attention in making source-codes using language such as Java and that does not require additional special instructions for compilers which convert source-codes to a function of execution format such as byte-code, wherein in execution of an invoking function of execution format such as byte-code of a JVM, the invoking function to be executed is substituted by an alternative function prepared beforehand and the alternative function which has substituted is executed, so as to realize the above-mentioned process of re-utilizing the function record area.
Further object of the present invention is to provide a function execution method, and the like, that can decrease total processing load and make the function record area appropriate by utilizing the secured function record area as it is when the invoking function is the same as the invoked function, and changing the secured function record area according to a format of the invoked function when the invoking function is different from the invoked function.